<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/">
        <xsl:if test="count(//stock) = 0">
            <p style="font-weight:bold; margin-top: 10px; font-size: 16px;">Aucun produit pour votre critere</p>
        </xsl:if>
        <xsl:for-each select="//stock">

            <li class="product first" style="text-align:center; padding-right:20px; margin-bottom:5px;">

                <div style="width:250px; border:1px solid #E2E2E2; padding:10px;">

                    <table style="width:100%;">
                        <tr>
                            <td>
                                <img src="{concat('../produits/', product/@id,'.jpg')}" />
                            </td>
                            <td style="text-align:left;">
                                <b>Produit : </b>
                                <a style="display:inline; padding:0px; margin:0px; height:0px; line-height:0px;" href="{concat('../user/ProductByName.do?name=', product/name)}">
                                    <xsl:value-of select="product/name" />
                                </a>
                                <br />
                                <b>Prix : </b>
                                <xsl:value-of select="concat(price, ' ', price/@currency)" />
                                <br />
                                <xsl:choose>
                                    <xsl:when test="quantity &lt; 1">
                                Quantité : indisponible
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <b>Quantité : </b>
                                        <xsl:value-of select="quantity" />
                                        <br />
                                        <form>
                                            <xsl:attribute name="action">../user/AddLineInCart.do</xsl:attribute>
                                            <xsl:attribute name="onSubmit"> 
                                                <xsl:value-of select="concat('return check_value_in_range(this.quantity, 1, ', quantity, ')')" />
                                            </xsl:attribute>

                                            <input name="id_store" value="{store/@id}" type="hidden" />
                                            <input name="id_product" value="{product/@id}" type="hidden" />
                                            <input name="action" value="add" type="hidden" />
                                            <input>
                                                <xsl:attribute name="type">text</xsl:attribute>
                                                <xsl:attribute name="name">quantity</xsl:attribute>
                                                <xsl:attribute name="size">1</xsl:attribute>
                                                <xsl:attribute name="value">0</xsl:attribute>
                                                <xsl:attribute name="onChange">
                                                    <xsl:value-of select="concat('check_value_in_range(this, 1, ', quantity, ')')" />
                                                </xsl:attribute>
                                            </input>
                                            <input type="submit" value="Commander"></input>
                                        </form>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <b>Magasin : </b>
                                <a href="{concat('../user/ProductByStore.do?id=', store/@id)}">
                                    <xsl:value-of select="store/name" />
                                </a>
                            </td>
                        </tr>

                    </table>
                    
                    <div style="clear:both;"></div>
                </div>
            </li>

        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>